<?php
/**
 * This file is part of the Yacms (http://www.yacms.org)
 * Copyright (c) 2019 gylr0505 (http://www.yacms.org)
 *
 * Author: 鬼一浪人 <gylr0505@163.com>
 *
 * DateTime: 19-10-29 下午9:41
 * Description:
 */
 
declare(strict_types = 1);

namespace App\Template\Log;

use Carbon\Carbon;


trait LogTrait
{
    protected $template_log_hash_prefix = 'template_log_hash_key_prefix';

    /**
     * @return string
     */
    public function generatorCurrentCacheHashKey()
    {
        return $this->template_log_hash_prefix .':'.
            Carbon::now(new \DateTimeZone('PRC'))->format('Y-m-d H:i').
            ':'.$this->id;
    }

    /**
     * @return string
     */
    public function generatorLastCacheHashKey()
    {
        $time = Carbon::now(new \DateTimeZone('PRC'));
        $time->subMinute();
        return $this->template_log_hash_prefix .':'.
            $time->format('Y-m-d H:i').
            ':'.$this->id;
    }

    /**
     * @return string
     */
    public function parseField()
    {
        return $this->is_success ? 'success' : 'fail';
    }
}